<?php

session_start();
require_once( "../includes/all.php" );

$crash = 0;

if ( !defined( "IN_MDM" ) )
  die;

if ( !defined( "IN_LOGIN" ) ) {

  if ( !( array_key_exists("uid", $_SESSION) ) ) {
    header("Location: login.php");
    die;
  }

  // Make acl calls
  $uid    = $_SESSION[ 'uid' ];
  $uname  = get_username( $uid );
  $uflags = get_flags( $uid );

  if ( defined( "CUR_FLAG" ) ) {
    // need to check flag
  
    if ( !has_flag( $uid, CUR_FLAG ) ) {
      // might want to redirect or something here, eventually...
      $crash = 1;
    }
  }
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-gb" xml:lang="en-gb">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <meta http-equiv="Content-Language" content="en-gb" />
    <meta http-equiv="imagetoolbar" content="no" />
    <title><?php echo ( defined("CUR_PAGE_TITLE") ? CUR_PAGE_TITLE : "Untitled" ); ?></title>
    <link href="styles/admin2.css" rel="stylesheet" type="text/css" media="screen" />
    <?php
    
    if ( defined("HEAD_INCLUDE_FILE") )
      include HEAD_INCLUDE_FILE;
      
    ?>
  </head>
  <body class="ltr">
    <div id="wrap">
      <div id="page-header">
        <h1>E2E Control Panel</h1>
        <p><a href="./index.php">Admin index</a> &bull; <a href="../">E2E index</a></p>
      </div>
      
      <div id="page-body">
       
        <div id="acp">
          <div class="panel">
            <span class="corners-top"><span></span></span>
            <div id="content">
              <?php
              
              if ( !defined("IN_LOGIN") ) {
              
              ?>
              
              <div id="menu">
                
                <p>Logged in as:<br /><?php 
                
                $uname = isset($uname) ? $uname : "Unknown User"; 
                // $append = in_array("super", $uflags) ? " (<em>super</em>)" : "";
                $append = "";
                
                echo "<strong>$uname</strong>" . $append;
                
                ?> [&nbsp;<a href="./logout.php">Logout</a>&nbsp;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
                
                <ul>
                  <?php
                  
                  // echo table of contents here
                  
                  $menu = ui_get_admin_menu( $uid );
                  
                  foreach ( $menu as $cat_id => $cat_arr ) {
                    $cat_title = $cat_arr[ 0 ];
                    $cat_children = $cat_arr[ 1 ];
                    
                    echo "<li class=\"header\">$cat_title</li>\n";
                    
                    foreach ( $cat_children as $child_arr ) {
                      $title = $child_arr[ 0 ];
                      $href  = $child_arr[ 1 ];
                      echo "<li><a href=\"$href\"><span>$title</span></a></li>\n";
                    }
                  }
                  
                  ?>
                  
                </ul>
              </div>

              <?php
              
              }
              
              ?>              
              <div id="main">
                <a name="maincontent"></a>
                <h1><?php echo CUR_PAGE_TITLE; ?></h1><hr />
                <?php
                
                if ( $crash ) {
                  echo ui_error("You do not possess the <strong>" . CUR_FLAG . "</strong> permission.");
                  include 'footer.php';
                  die;
                  
                }
                
                if ( array_key_exists( "MESSAGE", $_SESSION ) ) {
                  // Echo the message and then unset it.
                  $box = $_SESSION["MESSAGE"][ 0 ] ? "errorbox" : "successbox";
                  $head = $_SESSION["MESSAGE"][ 0 ] ? "Error" : "Information";
                  
                  echo "<div class=\"$box\">";
                  echo "<strong>$head</strong><br /><br />";
                  echo $_SESSION["MESSAGE"][ 1 ];
                  unset($_SESSION["MESSAGE"]);
                  echo "</div>";
                }
                
                ?>